package middleware

import (
	"github.com/fastknifes/usdt-pay/internal/http/common/utils"

	"github.com/gogf/gf/v2/net/ghttp"
)

func CommonMiddleware(req *ghttp.Request) {
	utils.SetRequest(req)

	// 设置跨域头部
	req.Response.Header().Set("Access-Control-Allow-Origin", "*")
	req.Response.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
	req.Response.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")

	if req.Method == "OPTIONS" {
		req.Response.WriteHeader(204) // 处理预检请求
		return
	}

	req.Middleware.Next()
}
